
import pprint

from ezcrc16 import verifyLen
from ezcrc16 import verifyCRC

pp = pprint.PrettyPrinter(indent=4)


class Captor:

  def __init__(self, dongle):
    self.dongle = dongle

  def readData(self):
    # FE FE FE FE 68 AA AA AA AA AA AA 68 11 04 35 33 33 39 B5 16
    request = "\xFE\xFE\xFE\xFE\x68\xAA\xAA\xAA\xAA\xAA\xAA\x68\x11\x04\x35\x33\x33\x39\xB5\x16"
    print "Power request L=",len(request)," - "+pp.pformat(request)+" ..."
    self.dongle.write(request)

    print "Power waiting answer ..."
    resp = self.dongle.read(1)
    if (verifyLen(resp, 40)):
      print "Power answer "+pp.pformat(resp)+" ..."
      print "P_ret:"+pp.pformat(resp)
      # Status, V, I, P, E
      return (True, 234.1, 0.76, 156.1, 934.8)
    # end if
    return (False, 0.0, 0.0, 0.0, 0.0)

  # end def

# end class
